// composables/useEventChannel.js
import {
	ref,
	onUnmounted
} from 'vue'

export default function useEventChannel() {
	const listeners = ref(new Map())

	const on = (event, callback) => {
		console.log('on....', event)
		listeners.value.set(event, callback)
	}

	const emit = (event, data) => {
		console.log('emit....', event)
		const callback = listeners.value.get(event)
		callback?.(data)
	}

	onUnmounted(() => {
		listeners.value.clear()
	})

	return {
		on,
		emit
	}
}